<?php



namespace App\Http\Requests\Company;

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;

class AttachRequest extends BaseRequest
{
    public function rules()
    {
        return [
            'file' => 'required|mimes:zip,pdf,jpeg,jpg,gif,png,md,doc,txt,csv,xlsx,xls,xlsm|max:3072',
        ];
    }

    public function messages()
    {


        return [
            'file.required' => __('请上传文件'),
            'file.mimes' => __('请上传:format格式文件', ['format' => 'zip,pdf,jpeg,jpg,gif,png,md,doc,txt,csv,xlsx,xls,docx']),
            'file.max' => __('请上传文件大小不能超3M'),
        ];
    }

    public function filldata()
    {

        $user = Auth::user();
        $url='';
        $path='';
        if ($this->hasFile('file')) {
            $file = $this->file('file');
            $size = $file->getSize();
            $disk = config('zesow.upload.attach.course.disk');
            $prefix = '/attaches/'.date("Ymd");
            $path = $this->file('file')->store( $prefix, ['disk' => $disk]);
            $data['extension'] = $file->getClientOriginalExtension();
            $data['size'] = $size;
            $data['title'] =pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME).".".$file->getClientOriginalExtension();
            $data['disk'] = config('zesow.upload.attach.course.disk');
            $url = url(\Illuminate\Support\Facades\Storage::disk($disk)->url($path));
        }

        $data['url'] = $url;
        $data['path'] = $path;
        $data['user_id'] =$user['app_id'];
        $data['company_id'] =$user['login_company_id'];


        return $data;
    }
}
